package com.example.demo.entity;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import lombok.extern.slf4j.Slf4j;

import java.util.Map;

@Slf4j
public class PayProxy {
    private IPay iPay;

    public void setInstance(String payType) {
        switch (payType){
            case "ali":this.iPay = new AliPay();break;
            case "wx": this.iPay = new WxPay();break;
            default:
                this.iPay = null;break;
        }
    }

    public void pay(Map<String, Object> paramsMap){
        prePay();
        this.iPay.pay(paramsMap);
        aferPay();
    }

    public void prePay(){
        log.info("class type : {}, run: {}",this.iPay.getClass().toString(), "prePay");
    }

    public void aferPay(){
        log.info("class type : {}, run: {}",this.iPay.getClass().toString(), "aferPay");
    }

}
